package com.framework.applogic;

import com.framework.model.Movie;

import java.util.List;

public class MovieHelper extends DriverBasedHelper {

    public MovieHelper(ApplicationManager app) {
        super(app.getWebDriver());
    }

    //Methods
    public MovieHelper create(Movie movie) {
        pages.mainPage.ensurePageLoaded().clickAddMovieButton().ensurePageLoaded()
                .setTitle(movie.getTitle())
                .setYear(movie.getYear())
                .clickSubmitButton();
        return this;
    }

    public boolean isCreated(Movie movie) {
        return pages.moviePage.isLoaded() && pages.moviePage.movieTitleIsPresent(movie);
    }

    public void remove() {
        pages.moviePage.ensurePageLoaded().clickRemoveButton().ensurePageLoaded();
    }

    public boolean checkMovieRemoved(String movieTitle) {
        return pages.mainPage.ensurePageLoaded().SearchMovie(movieTitle).checkNoMoviesFound();
    }

    public boolean checkNothingFound() {
        return pages.mainPage.ensurePageLoaded().checkNoMoviesFound();
    }

    public boolean isNoTitleErrorPresent() {
        return pages.addMoviePage.checkNoTitleError();
    }

    public boolean isNoYearErrorPresent() {
        return pages.addMoviePage.checkNoYearError();
    }

    public void searchMovie(String text) {
        pages.mainPage.SearchMovie(text).ensureContentLoaded();
    }

    public MovieHelper clearSearchField() {
        pages.mainPage.ensureContentLoaded().clearSearchField();
        return this;
    }

    public List<Movie> search(String title) {
        //
        return null;
    }

    public boolean checkMoviePresentInResults(String title) {
        return pages.mainPage.checkFirstMovieInResults(title);
    }
}
